package com.study.controller;

import com.study.entity.User;
import com.study.exception.ServiceException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：ihao ∶）
 * @date ：Created in 2020-11-29 12:36
 */
@RestController
public class test {


    @RequestMapping("/test")
    public List<User> test1() {
        User ll = User.builder().name("ll").age(18).build();
        List<User> users = new ArrayList<>();
        User ss = User.builder().name("2l").age(18).build();
        users.add(ss);
        users.add(ll);
        return users;
    }

    @RequestMapping("/test2")
    public User test2(Integer age) {
        User ll = User.builder().name("ll").age(age).build();
        if (age == null){
            throw new ServiceException("参数错误", 2003);
        }else if (age == 1){
            throw new ServiceException("手动异常");
        }
        return ll;
    }
}
